#!/usr/bin/python3
#coding=utf-8


import os
import sys
import time
import datetime
from log import CLog


today = datetime.datetime.now().strftime('%Y%m%d')
execLog = CLog(logName="checkRemQuoteCTP" + today + ".log", isPrint=True)

shengliFile = sys.argv[1]
ctpFile = sys.argv[2]
shengliQuote = {"": [""]}
ctpQuote = {"": [""]}

def loadQuote(shengli="", ctp =""):
    if shengli=="" or ctp == "":
        execLog("quote name param is empty!")
        return

    shengliQuoteRead = open(shengli, mode="r")
    lines = shengliQuoteRead.readlines()
    for line in lines:
        tradingDate = line.split(",", -1)[0]
        if "TradingDay" == tradingDate:
            continue
        symbol = line.split(",", -1)[1]
        if symbol not in shengliQuote.keys():
            shengliQuote.update({symbol: [line]})
        else:
            shengliQuote[symbol].append(line)

    ctpQuoteRead = open(ctp, mode="r")
    lines = ctpQuoteRead.readlines()
    for line in lines:
        tradingDate = line.split(",", -1)[0]
        if "TradingDay" == tradingDate:
            continue
        symbol = line.split(",", -1)[1]
        if symbol not in ctpQuote.keys():
            ctpQuote.update({symbol: [line]})
        ctpQuote[symbol].append(line)


loadQuote(shengli=shengliFile, ctp=ctpFile)
if len(shengliQuote) != len(ctpQuote):
    execLog.log("shengli symbol count " + str(len(shengliQuote) - 1) + " ctp quote count" + str(len(ctpQuote) - 1))
for symbol in shengliQuote.keys():
    if symbol not in ctpQuote.keys():
        execLog.log(symbol + " in shengli but not in ctp ")
for symbol in ctpQuote.keys():
    if symbol not in shengliQuote.keys():
        execLog.log(symbol + " in ctp but not in shengli")
    ctpQuotes = ctpQuote[symbol]
    shengliQuotes = shengliQuote[symbol]
    if len(shengliQuotes) != len(ctpQuotes):
        execLog.log((symbol + " shengli quote count not equal to ctp quote count " + str(len(shengliQuotes)) +"|" + str(len(ctpQuotes))))

    for i in range(1, len(shengliQuotes)):
        ctpQuoteLine = ctpQuotes[i]
        shengliQuoteLine = shengliQuotes[i]
        if ctpQuoteLine != shengliQuoteLine:
            execLog.log((symbol + " shengli quote line not equal to ctp quote line " + shengliQuoteLine + "|" + ctpQuoteLine))


